package com.hu.zhcc.shiro.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.dao.AssessResultMapper;
import com.hu.zhcc.shiro.entity.bo.AssessResult;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class AssessResultServiceImpl implements AssessResultService{
    @Autowired
    AssessResultMapper assessResultMapper;
    @Override
    public PageInfo<AssessResult> getAssessResultByName(Integer offset, Integer limit, String name, Integer type) {
        PageHelper.startPage(offset,limit);
        List<AssessResult> result = assessResultMapper.getAssessResultByName(name,type);
        PageInfo<AssessResult> p = new PageInfo<>(result);
        return p;
    }

    @Override
    public PageInfo<AssessResult> listAllAssessResult(Integer offset, Integer limit) {
        return null;
    }

    @Override
    public AssessResult getAssessResult(Integer id) {
        AssessResult assessResult = assessResultMapper.selectByPrimaryKey(id);
        return assessResult;
    }

    @Override
    public int updateAssessResult(AssessResult assessResult) {
        int i = assessResultMapper.updateByPrimaryKeySelective(assessResult);
        return i;
    }

    @Override
    public int addAssessResult(AssessResult assessResult) {
        assessResult.setMemberId(0);
        assessResult.setAssessDate(new Date());
        JSONArray jsonarray = new JSONArray(assessResult.getQuestionnaireAnswer());

        assessResult.setAssessItem1("是");
        assessResult.setAssessItem2("是");
        assessResult.setAssessItem3("否");
        assessResult.setAssessItem4("是");
        assessResult.setAssessItem5("否");
        assessResult.setAssessItem6("否");
        assessResult.setAssessItem7("否");
        assessResult.setAssessItem8("否");
        assessResult.setAssessItem9("否");

        assessResult.setFlag(0);
        int i = assessResultMapper.insertSelective(assessResult);
        return i;
    }

    @Override
    public int deleteAssessResult(Integer id) {
        int i = assessResultMapper.deleteByPrimaryKey(id);
        return i;
    }

}
